setlocal
set logfile=%StartupLogs%\configAdvancedLogging.log

%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"fields.[id='GW-TOTAL-RESPONSETIME', category = 'Default', sourceType ='ServerVariable', sourceName = 'GW-TOTAL-RESPONSETIME', logHeaderName='GW-TOTAL-RESPONSETIME']" >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"fields.[id='GW-ARR-OVERHEAD', category = 'Default', sourceType ='ServerVariable', sourceName = 'GW-ARR-OVERHEAD', logHeaderName='GW-ARR-OVERHEAD']" >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"fields.[id='GW-TOTAL-OVERHEAD', category = 'Default', sourceType ='ServerVariable', sourceName = 'GW-TOTAL-OVERHEAD', logHeaderName='GW-TOTAL-OVERHEAD']" >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"fields.[id='GW-EXTERNAL-RESPONSETIME', category = 'Default', sourceType ='ServerVariable', sourceName = 'GW-EXTERNAL-RESPONSETIME', logHeaderName='GW-EXTERNAL-RESPONSETIME']" >> %logfile% 2>&1

%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway', enabled='True', logROllOption='Schedule', schedule='Hourly', publishLogEvent='False']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='UserName',logHeaderName='cs-username']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='User Agent',logHeaderName='cs(User-Agent)']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='URI-Querystring',logHeaderName='cs-uri-query']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='Time-UTC',logHeaderName='time']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='Status',logHeaderName='sc-status']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='Server-IP',logHeaderName='s-ip']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='Server Port',logHeaderName='s-port']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='Server Name',logHeaderName='s-computername']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='RequestsPerSecond',logHeaderName='RequestsPerSecond']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='Method',logHeaderName='cs-method']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='Host',logHeaderName='cs(Host)']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='EndRequest-UTC',logHeaderName='EndRequest-UTC']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='CPU-Utilization',logHeaderName='CPU-Utilization']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='Cookie',logHeaderName='cs(Cookie)']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='ContentPath',logHeaderName='s-contentpath']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='Client-IP',logHeaderName='c-ip']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='Bytes Sent',logHeaderName='sc-bytes']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='Bytes Received',logHeaderName='cs-bytes']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='BeginRequest-UTC',logHeaderName='BeginRequest-UTC']" /commit:apphost  >> %logfile% 2>&1

%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='GW-TOTAL-RESPONSETIME',logHeaderName='GW-TOTAL-RESPONSETIME']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='GW-ARR-OVERHEAD',logHeaderName='GW-ARR-OVERHEAD']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='GW-TOTAL-OVERHEAD',logHeaderName='GW-TOTAL-OVERHEAD']" /commit:apphost  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /+"logDefinitions.[baseFileName='Gateway'].selectedFields.[id='GW-EXTERNAL-RESPONSETIME',logHeaderName='GW-EXTERNAL-RESPONSETIME']" /commit:apphost  >> %logfile% 2>&1

%windir%\system32\inetsrv\appcmd.exe set config -section:system.applicationHost/advancedLogging /serverLogs.directory:"%LogLocation%server-logs"  >> %logfile% 2>&1
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/advancedLogging/server /enabled:true /commit:apphost  >> %logfile% 2>&1

EXIT /B 0